<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="任务id" prop="wordId">
      <el-input v-model="dataForm.wordId" placeholder="任务id"></el-input>
    </el-form-item>
    <el-form-item label="任务名" prop="wordName">
      <el-input v-model="dataForm.wordName" placeholder="任务名"></el-input>
    </el-form-item>
    <el-form-item label="设备id" prop="phoneId">
      <el-input v-model="dataForm.phoneId" placeholder="设备id"></el-input>
    </el-form-item>
    <el-form-item label="评论开始" prop="commentDelayStart">
      <el-input v-model="dataForm.commentDelayStart" placeholder="评论开始"></el-input>
    </el-form-item>
    <el-form-item label="评论结束" prop="commentDelayEnd">
      <el-input v-model="dataForm.commentDelayEnd" placeholder="评论结束"></el-input>
    </el-form-item>
    <el-form-item label="发送开始" prop="commentSendStart">
      <el-input v-model="dataForm.commentSendStart" placeholder="发送开始"></el-input>
    </el-form-item>
    <el-form-item label="发送结束" prop="commentSendEnd">
      <el-input v-model="dataForm.commentSendEnd" placeholder="发送结束"></el-input>
    </el-form-item>
    <el-form-item label="评论类型" prop="commentType">
      <el-input v-model="dataForm.commentType" placeholder="评论类型"></el-input>
    </el-form-item>
    <el-form-item label="任务时长" prop="alarmTimeDelay">
      <el-input v-model="dataForm.alarmTimeDelay" placeholder="任务时长"></el-input>
    </el-form-item>
    <el-form-item label="喜欢概率" prop="rateLike">
      <el-input v-model="dataForm.rateLike" placeholder="喜欢概率"></el-input>
    </el-form-item>
    <el-form-item label="评论概率" prop="rateComment">
      <el-input v-model="dataForm.rateComment" placeholder="评论概率"></el-input>
    </el-form-item>
    <el-form-item label="收藏概率" prop="keepPro">
      <el-input v-model="dataForm.keepPro" placeholder="收藏概率"></el-input>
    </el-form-item>
    <el-form-item label="转发概率" prop="forwardPro">
      <el-input v-model="dataForm.forwardPro" placeholder="转发概率"></el-input>
    </el-form-item>
    <el-form-item label="浏览主页概率" prop="watchMainPro">
      <el-input v-model="dataForm.watchMainPro" placeholder="浏览主页概率"></el-input>
    </el-form-item>
    <el-form-item label="是否关注(1是0非)" prop="isAtten">
      <el-input v-model="dataForm.isAtten" placeholder="是否关注(1是0非)"></el-input>
    </el-form-item>
    <el-form-item label="关注概率" prop="attenPro">
      <el-input v-model="dataForm.attenPro" placeholder="关注概率"></el-input>
    </el-form-item>
    <el-form-item label="是否智能评论（1是0非）" prop="isSmartComment">
      <el-input v-model="dataForm.isSmartComment" placeholder="是否智能评论（1是0非）"></el-input>
    </el-form-item>
    <el-form-item label="评论关键词" prop="keyWords">
      <el-input v-model="dataForm.keyWords" placeholder="评论关键词"></el-input>
    </el-form-item>
    <el-form-item label="浏览作品时长{"start":1,"end":3}" prop="watchTime">
      <el-input v-model="dataForm.watchTime" placeholder="浏览作品时长{"start":1,"end":3}"></el-input>
    </el-form-item>
    <el-form-item label="设备状态" prop="phoneState">
      <el-input v-model="dataForm.phoneState" placeholder="设备状态"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          wordId: '',
          wordName: '',
          phoneId: '',
          commentDelayStart: '',
          commentDelayEnd: '',
          commentSendStart: '',
          commentSendEnd: '',
          commentType: '',
          alarmTimeDelay: '',
          rateLike: '',
          rateComment: '',
          keepPro: '',
          forwardPro: '',
          watchMainPro: '',
          isAtten: '',
          attenPro: '',
          isSmartComment: '',
          keyWords: '',
          watchTime: '',
          phoneState: '',
          createTime: ''
        },
        dataRule: {
          wordId: [
            { required: true, message: '任务id不能为空', trigger: 'blur' }
          ],
          wordName: [
            { required: true, message: '任务名不能为空', trigger: 'blur' }
          ],
          phoneId: [
            { required: true, message: '设备id不能为空', trigger: 'blur' }
          ],
          commentDelayStart: [
            { required: true, message: '评论开始不能为空', trigger: 'blur' }
          ],
          commentDelayEnd: [
            { required: true, message: '评论结束不能为空', trigger: 'blur' }
          ],
          commentSendStart: [
            { required: true, message: '发送开始不能为空', trigger: 'blur' }
          ],
          commentSendEnd: [
            { required: true, message: '发送结束不能为空', trigger: 'blur' }
          ],
          commentType: [
            { required: true, message: '评论类型不能为空', trigger: 'blur' }
          ],
          alarmTimeDelay: [
            { required: true, message: '任务时长不能为空', trigger: 'blur' }
          ],
          rateLike: [
            { required: true, message: '喜欢概率不能为空', trigger: 'blur' }
          ],
          rateComment: [
            { required: true, message: '评论概率不能为空', trigger: 'blur' }
          ],
          keepPro: [
            { required: true, message: '收藏概率不能为空', trigger: 'blur' }
          ],
          forwardPro: [
            { required: true, message: '转发概率不能为空', trigger: 'blur' }
          ],
          watchMainPro: [
            { required: true, message: '浏览主页概率不能为空', trigger: 'blur' }
          ],
          isAtten: [
            { required: true, message: '是否关注(1是0非)不能为空', trigger: 'blur' }
          ],
          attenPro: [
            { required: true, message: '关注概率不能为空', trigger: 'blur' }
          ],
          isSmartComment: [
            { required: true, message: '是否智能评论（1是0非）不能为空', trigger: 'blur' }
          ],
          keyWords: [
            { required: true, message: '评论关键词不能为空', trigger: 'blur' }
          ],
          watchTime: [
            { required: true, message: '浏览作品时长{"start":1,"end":3}不能为空', trigger: 'blur' }
          ],
          phoneState: [
            { required: true, message: '设备状态不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/admin/accountup/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.wordId = data.accountUp.wordId
                this.dataForm.wordName = data.accountUp.wordName
                this.dataForm.phoneId = data.accountUp.phoneId
                this.dataForm.commentDelayStart = data.accountUp.commentDelayStart
                this.dataForm.commentDelayEnd = data.accountUp.commentDelayEnd
                this.dataForm.commentSendStart = data.accountUp.commentSendStart
                this.dataForm.commentSendEnd = data.accountUp.commentSendEnd
                this.dataForm.commentType = data.accountUp.commentType
                this.dataForm.alarmTimeDelay = data.accountUp.alarmTimeDelay
                this.dataForm.rateLike = data.accountUp.rateLike
                this.dataForm.rateComment = data.accountUp.rateComment
                this.dataForm.keepPro = data.accountUp.keepPro
                this.dataForm.forwardPro = data.accountUp.forwardPro
                this.dataForm.watchMainPro = data.accountUp.watchMainPro
                this.dataForm.isAtten = data.accountUp.isAtten
                this.dataForm.attenPro = data.accountUp.attenPro
                this.dataForm.isSmartComment = data.accountUp.isSmartComment
                this.dataForm.keyWords = data.accountUp.keyWords
                this.dataForm.watchTime = data.accountUp.watchTime
                this.dataForm.phoneState = data.accountUp.phoneState
                this.dataForm.createTime = data.accountUp.createTime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/admin/accountup/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'wordId': this.dataForm.wordId,
                'wordName': this.dataForm.wordName,
                'phoneId': this.dataForm.phoneId,
                'commentDelayStart': this.dataForm.commentDelayStart,
                'commentDelayEnd': this.dataForm.commentDelayEnd,
                'commentSendStart': this.dataForm.commentSendStart,
                'commentSendEnd': this.dataForm.commentSendEnd,
                'commentType': this.dataForm.commentType,
                'alarmTimeDelay': this.dataForm.alarmTimeDelay,
                'rateLike': this.dataForm.rateLike,
                'rateComment': this.dataForm.rateComment,
                'keepPro': this.dataForm.keepPro,
                'forwardPro': this.dataForm.forwardPro,
                'watchMainPro': this.dataForm.watchMainPro,
                'isAtten': this.dataForm.isAtten,
                'attenPro': this.dataForm.attenPro,
                'isSmartComment': this.dataForm.isSmartComment,
                'keyWords': this.dataForm.keyWords,
                'watchTime': this.dataForm.watchTime,
                'phoneState': this.dataForm.phoneState,
                'createTime': this.dataForm.createTime
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
